﻿using System.Linq;
using System.Data.Entity;
using System.Web.Mvc;
using VOD.Models;
using PagedList;

namespace VOD.Controllers
{
    public class VarietyController : Controller
    {
        private readonly VODEntities _db = new VODEntities();
        // 综艺首页
        // GET: /Variety/
        public ActionResult Index(int? areaID=2,int? page=1)
        {
            var videos = _db.Videos
                .Include(v => v.VideoUrls)
                .Where(v => v.Recycled != 1 && v.CategoryID == 5)
                .OrderByDescending(v=>v.UpdateDate)
                .ToList();
            areaID = areaID ?? 2;
            videos = videos.Where(v => v.AreaID == areaID).ToList();
            int pageSize = 10;//定义每页显示的记录数
            int pageIndex = (page ?? 1) - 1;
            int pageNumber = page ?? 1;
            return View(videos.ToPagedList(pageNumber, pageSize));
        }

        /// <summary>
        /// 频道排行榜
        /// </summary>
        /// <returns></returns>
        public ActionResult Rank()
        {
            var videos = _db.Videos
                .Where(v=>v.CategoryID==5 && v.Recycled!=1)
                .Include(v => v.PlayRecords)
                .OrderByDescending(v => v.PlayRecords.Count)
                .Take(10);
            return View(videos);
        }

        protected override void Dispose(bool disposing)
        {
            _db.Dispose();
            base.Dispose(disposing);
        }
    }
}
